package com.ktwlsoft.fundmanage.domain.repository;

import com.ktwlsoft.fundmanage.domain.entity.BusinessProtocol;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BusinessProtocolRepository extends JpaRepository<BusinessProtocol, Long> {

    BusinessProtocol findByTsCode(long tsCode);

    List<BusinessProtocol> findByTsCodeAndPrinted(long tsCode, boolean printed);

    @Query(value = "select b.* from business_protocol b where b.ts_code=:tsCode order by b.created_at desc LIMIT 1", nativeQuery = true)
    BusinessProtocol findByTsCodeLatest(long tsCode);

    @Query(value = "select b.* from business_protocol b where b.ts_code=:tsCode and b.approval=:approval order by b.created_at desc LIMIT 1", nativeQuery = true)
    BusinessProtocol findByTsCodeAndApprovalLatest(long tsCode, boolean approval);
}
